import 'package:flutter/material.dart';

import 'package:testui/test04/scroll/LearnAnimatedList.dart';
import 'package:testui/test04/scroll/LearnController.dart';
import 'package:testui/test04/scroll/LearnCustomScrollView.dart';
import 'package:testui/test04/scroll/LearnGrdView.dart';
import 'package:testui/test04/scroll/LearnListView.dart';
import 'package:testui/test04/scroll/LearnNestedScrollView.dart';
import 'package:testui/test04/scroll/LearnScrollerCache.dart';
import 'package:testui/test04/scroll/LearnSingleChildScrollView.dart';
import 'package:testui/test04/scroll/LearnTabBarView.dart';

import 'LearnPageView.dart';

///
/// Flutter 中的可滚动主要由三个角色组成：Scrollable、Viewport 和 Sliver：
///
///  Scrollable ：用于处理滑动手势，确定滑动偏移，滑动偏移变化时构建 Viewport 。
///  Viewport：显示的视窗，即列表的可视区域；
///   Sliver：视窗里显示的元素。
///
///
class AllScrollListPage extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("滚动型控件"),
      ),
      body: getItemList(),
    );
  }


}

getItemList() {
  var list = ["SingleChildScrollView","ListView","滚动监听及控制",
    "AnimatedList","GridView","PageView",
  "可滚动组件子项缓存","TabBarView","CustomScrollView","NestedScrollView"];

  return ListView.separated( itemCount: list.length,
      itemBuilder: (context,index){
        return ListTile(
          title: Text(list[index]),
          onTap: (){
            onSelectNext(context,index);
          },
        );
      },separatorBuilder:(context,index){
        return Divider(
          color: Colors.black12,
          height: 1,
        );
      });

}

void onSelectNext(BuildContext context, int index) {
  Navigator.of(context).push(MaterialPageRoute(builder: (context) {
    if(index ==0){
      return  SingleChildScrollViewPage();
    }else if(index ==1){
      return ListViewViewPage();
    }else if(index ==2){
      return ListViewControllerViewPage();
    }else if(index ==3){
      return AnimatedListSample();
    }else if(index ==4){
      return GridViewPage();
    }else if(index ==5){
      return PageViewPage();
    }else if(index ==6){
      return ScrollerCacheViewPage();
    }else if(index ==7){
      return TabBarViewViewPage();
    }else if(index ==8){
      return CustomScrollViewPage();
    }else if(index ==9){
      return NestedScrollViewPage();
    } else {
      return SingleChildScrollViewPage();
    }
  }));
}


